#pragma once

#include "common.hpp"




class ToolHttp{
    // static void Filesize(const std::string& filename){
    // }
public:

    static bool GetfileContent(std::string& filename,std::string* out)
    {
        //version2
        int filesize = Filesize(filename);
        if(filesize > 0){
            std::ifstream in(filename);
            if(!in.is_open()){
                return false;
            }
            out->resize(filesize);// 扩容
            in.read(&(*out)[0],filesize);
            in.close();
        }else{
            LOG(level::DEBUG)<<"size <= 0";
            return false;
        }
        return true;
    }

    static bool Readoneline(std::string& reqstr, std::string* in){
        auto pos = reqstr.find(line_break);
        if(pos == std::string::npos)
            return false;

        *in = reqstr.substr(0,pos);
        reqstr.erase(0,pos);

        return true;
    }

    static int Filesize(std::string& filename)
    {
        std::ifstream in(filename,std::ios::binary);
        if(!in.is_open()){
            return -1;
        }
        in.seekg(0,in.end);//光标到最后
        int fliesize = in.tellg();
        in.seekg(0,in.beg);
        in.close();
        return fliesize;
    }
    
};